package com.itxiaoz.config;

import com.itdupan.utils.RsaUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @Author: Teao
 * @CreateTime: 2024-04-17  01:12
 * @Description:
 */
@Component
@Slf4j
@ConfigurationProperties(prefix = "itdupan.jwt")
public class JwtProperties {

    private String pubKeyPath;
    private String cookieName;  //
    private PublicKey publicKey; // 公钥

    private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class);
    @PostConstruct
    public void init(){
        try {
            // 读取公钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        }catch (Exception e){
            logger.error("初始化公钥和私钥失败！",e);
            throw new RuntimeException();
        }
    }

    public String getPubKeyPath() {
        return pubKeyPath;
    }

    public void setPubKeyPath(String pubKeyPath) {
        this.pubKeyPath = pubKeyPath;
    }

    public String getCookieName() {
        return cookieName;
    }

    public void setCookieName(String cookieName) {
        this.cookieName = cookieName;
    }

    public PublicKey getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(PublicKey publicKey) {
        this.publicKey = publicKey;
    }

}
